<template>
  <div>
    <el-col :span="24" class="content_title">
      <el-col :span="12">
        <HeadTitle></HeadTitle>
      </el-col>
      <el-col :span="12"></el-col>
    </el-col>
    <el-col :span="24" class="bg_write pd_20">
      <!-- <div v-show="showTitle" class="alert alert-info disable-del"><h4>提示</h4>配置微信后，您将可以使用微信公众号相关接口功能，如会员信息获取，消息提醒，自定义菜单，消息回复等功能<a href="https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncement&amp;announce_id=115383153198yAvN&amp;version=&amp;lang=zh_CN&amp;token=" target="_blank">点击查看配置教程</a>。
                    <a href="" class="alert-delete" title="隐藏" @click.prevent="showTitle = false "><i class="gicon-remove"></i></a>
      </div>-->
      <div class="inner_container_box side_l cell_layout">
        <div class="inner_container_box_bd">
          <div class="inner_side f_l">
            <div class="bd">
              <div class="menu_manage">
                <div class="sub_title_bar light">
                  <h4>菜单管理</h4>
                  <div class="opr_wrp">
                    <a @click.prevent="addMenu(0)" class="opr_meta icon16_common add_gray">添加</a>
                    <a id="orderBt" class="opr_meta icon16_common sort_gray">排序</a>
                  </div>
                </div>
                <div class="inner_menu_box gray with_switch ui-sortable ui-sortable-disabled">
                  <dl
                    class="inner_menu jsMemu disabled"
                    v-show="yiMen"
                    v-for="(item,i) in yiMen"
                    :key="i"
                  >
                    <dt class="inner_menu_item jslevel1" :class="{selected : acTitle==item.title}">
                      <a
                        href="javascript:;"
                        @click.prevent="showMenu($event,item,i)"
                        class="inner_menu_link"
                      >
                        <strong>{{item.title}}</strong>
                      </a>
                      <span class="menu_opr">
                        <a class="icon14_common jsAddBt" @click.prevent="addMenu(item,i)"></a>
                        <a href class="icon14_common jsEditBt" @click.prevent="editMenu(item)"></a>
                        <a href class="icon14_common jsDelBt" @click.prevent="delMenu(item,i)"></a>
                        <a href class="m_sort" @click.prevent="upGo(yiMen,i)">
                          <i class="el-icon-sort-up"></i>
                        </a>
                        <a href="javascript:;" class="m_sort" @click.prevent="downGo(yiMen,i)">
                          <i class="el-icon-sort-down"></i>
                        </a>
                      </span>
                    </dt>
                    <dd
                      class="inner_menu_item jslevel2"
                      :class="{selected : acTitle==it.title}"
                      data-id="10"
                      v-show="item.z"
                      v-for="(it,index) in item.z"
                      :key="index"
                    >
                      <i class="icon_dot">●</i>
                      <a @click.prevent="showMenu($event,it,index)" class="inner_menu_link">
                        <strong>{{it.title}}</strong>
                      </a>
                      <span class="menu_opr">
                        <a
                          href="javascript:;"
                          @click.prevent="editErMenu(it)"
                          class="icon14_common edit_gray jsSubEditBt"
                        ></a>
                        <a
                          href="javascript:;"
                          class="icon14_common del_gray jsSubDelBt"
                          @click.prevent="delMenu(it,index,i)"
                        ></a>
                        <a href class="m_sort" @click.prevent="upGo(item.z,index)">
                          <i class="el-icon-sort-up"></i>
                        </a>
                        <a href="javascript:;" class="m_sort" @click.prevent="downGo(item.z,index)">
                          <i class="el-icon-sort-down"></i>
                        </a>
                      </span>
                    </dd>
                  </dl>
                </div>
              </div>
            </div>
          </div>
          <div class="inner_main f_r">
            <div class="bd">
              <div class="action_setting">
                <div class="sub_title_bar light">
                  <h4>设置动作</h4>
                  <el-button
                    :loading="$store.state.isLoading"
                    type="primary"
                    plain
                    style="float:right"
                    @click="fabuMenu"
                  >发布</el-button>
                </div>
              </div>
              <div class="action_content default jsMain" v-show="showDefault ==0">
                <p class="action_tips">你可以先添加一个菜单，然后开始为其设置响应动作</p>
              </div>
              <div class="action_content init jsMain" v-show="showDefault ==1">
                <p class="action_tips">请选择订阅者点击菜单后，公众号做出的相应动作</p>
                <!-- <a href="" @click.prevent="toTypes('信息')"><i class="icon_menu_action send"></i><strong>发送信息</strong></a> -->
                <a href @click.prevent="toTypes('url')">
                  <i class="icon_menu_action url"></i>
                  <strong>跳转到网页</strong>
                </a>
                <a @click.prevent="toTypes('app')" data-appid>
                  <i class="wx_app"></i>
                  <strong>打开小程序</strong>
                </a>
              </div>
              <div class="action_content default jsMain" v-show="showDefault ==2">
                <p class="action_tips">已有子菜单，无法设置动作</p>
              </div>

              <!-- 设置跳转链接 -->
              <div class="action_content url jsMain" v-show="showTypes=='url'">
                <el-form ref="formUrl" :model="formUrl" label-width="80px">
                  <p class="action_tips">订阅者点击该子菜单会跳到以下链接</p>
                  <div class="seleUrl">
                    <el-select v-model="urlitem" size="small" placeholder="请选择要链接的页面地址">
                      <el-option label="自定义链接" value></el-option>
                    </el-select>
                  </div>

                  <el-form-item class="left_form">
                    <el-input v-model="formUrl.value" size="small" :value="formUrl.value"></el-input>

                    <LinkMenu @sendRow="getSendRow"></LinkMenu>
                  </el-form-item>
                </el-form>
                <div class="tool_bar">
                  <a
                    class="btn btn-primary"
                    style="width:80px"
                    id="editSave"
                    @click.prevent="editSave(1)"
                  >保存</a>
                  <a
                    class="btn btn_default"
                    style="width:80px"
                    id="editBack"
                    @click.prevent="fanhui"
                  >返回</a>
                </div>
              </div>
              <div class="action_content url jsMain" v-show="showTypes=='app'">
                <el-form ref="form" :model="form" label-width="140px">
                  <el-form-item label="小程序的appid:" v-show="showTypes=='app'">
                    <el-input size="small" v-model="form.appid" :value="formUrl.appid"></el-input>
                    <span class="fi-help-text">添加已关联的小程序appid,如：wx286b93c14bbf93aa</span>
                  </el-form-item>

                  <el-form-item label="小程序的所在网址:" v-show="showTypes=='app'">
                    <el-input size="small" v-model="form.appUrl" :value="formUrl.value"></el-input>
                    <span class="fi-help-text">
                      请准确填写小程序所在网址, 如：http://mp.weixin.qq.com
                      <!-- 支持改写为小程序商品链接(后台-商品列表-小程序商品链接复制) -->
                    </span>
                  </el-form-item>

                  <el-form-item label="小程序的页面路径:" v-show="showTypes=='app'">
                    <el-input size="small" v-model="form.pagePath" :value="formUrl.pagepath"></el-input>
                    <span class="fi-help-text">请准确填写小程序路径, 默认路径为小程序首页,如：pages/index/index</span>
                  </el-form-item>
                </el-form>
                <div class="tool_bar">
                  <a class="btn btn-primary" style="width:80px" @click.prevent="editSave(8)">保存</a>
                  <a
                    class="btn btn_default"
                    style="width:80px"
                    id="editBack"
                    @click.prevent="fanhui"
                  >返回</a>
                </div>
              </div>

              <div class="action_content send jsMain" v-show="showTypes=='信息'">
                <p class="action_tips">订阅者点击该子菜单会收到以下消息</p>
                <div class="msg_sender small">
                  <div class="msg_tab">
                    <ul class="tab_navs">
                      <li class="tab_nav tab_text width5" @click="getTypes(1)" title="文字">
                        <a>
                          &nbsp;
                          <i
                            class="icon_msg_sender tips"
                            :class="{text_active : formUrl.types==1}"
                            data-types="0"
                          ></i>
                        </a>
                      </li>
                      <li class="tab_nav tab_img width5" @click="getTypes(2)" title="单图文">
                        <a>
                          &nbsp;
                          <i
                            class="icon_msg_sender tips"
                            :class="{oneImg_active : formUrl.types==2}"
                          ></i>
                        </a>
                      </li>
                      <li
                        class="tab_nav tab_appmsg width5 no_extra"
                        @click="getTypes(3)"
                        data-types="2"
                        title="多图文"
                      >
                        <a>
                          &nbsp;
                          <i
                            class="icon_msg_sender tips"
                            :class="{twoImg_active : formUrl.types==3}"
                          ></i>
                        </a>
                        <input type="radio" class="j-sendType" value="3" style="display:none;" />
                      </li>
                      <li class="tab_nav tab_img width5" @click="getTypes(4)" title="上传图片">
                        <a class="imgnav j-selectimg">
                          &nbsp;
                          <compressimgUpload
                            style="display:inline-block"
                            class
                            listType="text"
                            :wxmenu="true"
                            :wx="true"
                            :onSuccess="onSuccess"
                            :isOneImg="true"
                            :files="fileList"
                          ></compressimgUpload>
                        </a>
                        <input type="radio" class="j-sendType" value="4" style="display:none;" />
                      </li>
                      <li class="tab_nav tab_img width5" @click="getTypes(5)" title="商城名片">
                        <a class="imgnav j-selectimg">
                          &nbsp;
                          <i
                            class="icon_msg_sender tips mallcard"
                            :class="{mp_active : formUrl.types==5}"
                          ></i>
                        </a>
                        <input type="radio" class="j-sendType" value="11" style="display:none;" />
                      </li>
                    </ul>
                    <div class="tab_panel">
                      <div class="tab_content" v-show="formUrl.types == 1">
                        <div class="js_textArea inner no_extra tl">
                          <!-- <ueditor :server-url="UEditorUrl" v-model="formUrl.value" :z-index='21' ueditor-path='/ueditor/' :initial-frame-height='420' :auto-height-enabled='false' :options='config1'></ueditor> -->
                          <editor
                            class="editor_wx"
                            :config="config"
                            v-model="form.value"
                            upload-url="/api/common/upload/index/"
                            fileName="file"
                          />
                        </div>
                      </div>
                      <div class="tab_content" v-show="formUrl.types == 2 && danxuan">
                        <div class="js_textArea inner no_extra tl">
                          <dl class="materialPrePanel mgt20" style="border: 1px solid #E7E7EB;">
                            <dt>
                              <h1 class="single-title first-t">{{danxuan.title}}</h1>
                              <p
                                class="single-datetime first-d"
                              >{{danxuan.update_time | getTimeFormat }}</p>
                              <div class="cover-wrap">
                                <img :src="$fnc.getImgUrl(danxuan.piclink)" />
                              </div>
                              <p class="single-summary first-p">{{danxuan.content}}</p>
                              <a href="yuyu" target="_blank" class="single-link clearfix first-a">
                                <span class="f_l">阅读全文</span>
                                <span class="f_r symbol">&gt;</span>
                              </a>
                            </dt>
                          </dl>
                        </div>
                      </div>
                      <div class="tab_content" v-show="formUrl.types == 3">
                        <div class="js_textArea inner no_extra tl">
                          <dl class="materialPrePanel mgt20 bgcfff border">
                            <dt class="mb10 mt10" v-if=" zhuTitle">
                              <a href="awdfr" target="_blank">
                                <div class="cover-wrap">
                                  <img :src="$fnc.getImgUrl(zhuTitle.piclink)" class="img-cover" />
                                </div>
                                <h2 class="w262">{{zhuTitle.title}}</h2>
                              </a>
                            </dt>
                            <dd
                              class="newWidth"
                              v-show="fuTitle"
                              :key="i"
                              v-for="(item,i) in fuTitle"
                            >
                              <a class="border-top_1 p" href target="_blank">
                                <h3>{{item.title}}</h3>
                                <div class="pic">
                                  <img :src="+$fnc.getImgUrl(item.piclink)" class="img-cover" />
                                </div>
                              </a>
                            </dd>
                          </dl>
                        </div>
                      </div>
                      <div class="tab_content" v-if="formUrl.types==4 && imgUrl">
                        <div class="js_imgArea inner">
                          <img :src="imgUrl" alt />
                        </div>
                      </div>
                      <div class="tab_content" v-if="formUrl.types==5 ">
                        <div class="js_imgArea inner">
                          <img src="../../assets/img/tpl3.png" alt />
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="tool_bar">
                  <a
                    class="btn btn-primary"
                    style="width:80px"
                    id="editSave"
                    @click.prevent="editSave(0)"
                  >保存</a>
                  <a
                    class="btn btn_default"
                    style="width:80px"
                    id="editBack"
                    @click.prevent="fanhui"
                  >返回</a>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="tool_bar tc">
        <!-- <a  class="btn btn-primary" id="pubBt">发布</a>
        <a  class="btn " id="viewBt">预览</a>-->
      </div>
    </el-col>
    <el-dialog
      :close-on-click-modal="false"
      title="输入提示框"
      @close="closeDio"
      class="tl"
      width="600px"
      :visible.sync="dioWxMenu"
    >
      <div class="jbox-container">
        <div class="menu_notes">
          <label class="frm_label" for="menu_name_one">菜单名称名字不多于5个汉字或8个字母</label>
          <span class="frm_input_box">
            <input type="text" v-model="yimenus" class="frm_input" maxlength="8" />
          </span>
        </div>
      </div>
      <div class="jbox-buttons">
        <a href="javascript:;" @click="subWxMenu" class="jbox-buttons-ok btn btn-primary">确定</a>
        <a href="javascript:;" @click="dioWxMenu=false" class="jbox-buttons-ok btn">取消</a>
      </div>
    </el-dialog>
    <el-dialog
      :close-on-click-modal="false"
      title="输入提示框"
      class="tl"
      width="600px"
      :visible.sync="dioWxMenuEr"
    >
      <div class="jbox-container">
        <div class="menu_notes">
          <label class="frm_label" for="menu_name_one">菜单名称名字不多于5个汉字或8个字母</label>
          <span class="frm_input_box">
            <input type="text" v-model="form.title" class="frm_input" maxlength="8" />
          </span>
        </div>
      </div>
      <div class="jbox-buttons">
        <a href="javascript:;" @click="subWxMenuEr" class="jbox-buttons-ok btn btn-primary">确定</a>
        <a href="javascript:;" @click="dioWxMenuEr=false" class="jbox-buttons-ok btn">取消</a>
      </div>
    </el-dialog>
    <el-dialog
      :close-on-click-modal="false"
      :title="formUrl.types == 2 ? '选择单条图文' : '选择多条图文'"
      top="2vh"
      width="800px"
      :visible.sync=" dialogTableVisible "
    >
      <el-table ref="multipleTable" :data="onewenbData" max-height="450" tooltip-effect="dark">
        <el-table-column label="标题" min-width="300">
          <template slot-scope="scope">
            <div class="ng ng_single">
              <div class="ng_item">
                <div class="td_cont with_label">
                  <span class="label label-success">图文</span>
                  <div class="text">
                    <a
                      href="yuyu"
                      target="_blank"
                      class="part new_window"
                      :title="scope.row.title"
                    >{{scope.row.title}}</a>
                  </div>
                </div>
              </div>
              <div class="ng_item view_more">
                <a href="yuyu" class="td_cont clearfix new_window">
                  <span class="pull-left">阅读全文</span>
                  <span class="pull-right">&gt;</span>
                </a>
              </div>
            </div>
          </template>
        </el-table-column>

        <el-table-column label="创建时间" min-width="160">
          <template slot-scope="scope">{{ scope.row.update_time | getTimeFormat }}</template>
        </el-table-column>

        <el-table-column min-width="250">
          <template slot="header" slot-scope="scope">
            <span v-if="false">{{scope.row}}</span>
            <el-input v-model="search" size="mini" placeholder="输入关键字搜索" />
          </template>
          <template slot-scope="scope">
            <el-button
              :loading="$store.state.isLoading"
              size="mini"
              v-if="formUrl.types == 2 "
              :type="danxuan.id==scope.row.id ? 'success' : ''"
              @click="subItem(scope.row)"
            >选择</el-button>
            <el-button
              :loading="$store.state.isLoading"
              size="mini"
              :type="scope.row.id==zhuId ? 'success' : ''"
              v-if="formUrl.types == 3"
              @click="setZhu(scope.row)"
            >选择主标题</el-button>
            <el-button
              :loading="$store.state.isLoading"
              size="mini"
              :type="fuId.indexOf(scope.row.id)>=0? 'success' : ''"
              v-if="formUrl.types == 3"
              @click="setFu(scope.row)"
            >选择副标题</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="tr mar_top_20">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="all_num"
        ></el-pagination>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import HeadTitle from "@/components/currency/HeadTitle.vue";
// import ueditor from '@/components/ueditor/Ueditor.vue';
import editor from "@/components/currency/editor.vue";
import compressimgUpload from "@/components/currency/compressimgUpload.vue";
import LinkMenu from "@/components/currency/Link_menu.vue";
export default {
  components: {
    HeadTitle,
    editor,
    compressimgUpload,
    LinkMenu
  },
  data() {
    return {
      url_header: "",
      form: {
        id: "",
        title: ""
      },
      dioWxMenuEr: false,
      showTitle: true,
      dioWxMenu: false,
      showDefault: 0,
      yiMen: [],
      yimenus: "",
      addInedx: "",
      formUrl: {
        value: "",
        material: "",
        types: "1"
      },
      fileList: [],
      form: {
        appid: "",
        appUrl: ""
      },
      subForm: {
        title: ""
      },
      config1: {
        initialFrameWidth: "100%:",
        initialFrameHeight: 215,
        wordCount: false,
        initialContent: "",
        toolbars: [["removeformat", "link", "unlink"]]
      },
      config: {
        qllink: true
      },
      UEditorUrl: "",
      types: "",
      showEdit: 0,
      onewenbData: this.$store.state.wx_material.data,
      dialogTableVisible: false,
      danxuan: "",
      zhuTitle: "",
      fuTitle: [],
      imgUrl: "",
      search: "",
      zhuId: "",
      fuId: [],
      showTypes: "",
      updateId: "",
      urlitem: "",
      url: "",
      appid: "",
      appUrl: "",
      appPage: "",
      acTitle: "",
      pageSize: 10,
      currentPage: 1,
      all_num: this.$store.state.wx_material.all_num
    };
  },
  created() {
    this.UEditorUrl = "";
    this.getWxMenu();
    this.$api.getSettings.getSettingsList({ cate: "wx" }).then(res => {
      if (res.data.code == 200 && res.data.status == 1) {
        res.data.result.forEach(item => {
          if (item.title == "手机端网址") {
            this.url_header = item.value;
            // this.formUrl.value = item.value;
          }
        });
      } else {
        this.$fnc.alertError(res.data.code_desc, res.data.result);
      }
    });
  },
  methods: {
    getSendRow(row) {
      console.log(row);
      this.$store.dispatch("getShopsAll", { page: 1, page_size: 10 });
      if (row == null) return false;
      let index = row.index;
      // this.formUrl.value =
      //   window.location.protocol + "//" + window.location.host;
      this.formUrl.value = this.url_header;
      if (!row.disable && row.title == "自定义链接") {
        this.formUrl.value = "";
        return false;
      }
      if (row.url) {
        this.formUrl.value = this.formUrl.value + row.url;
      }
      if (row.url_title == "产品分类" && row.click_title == "供应商分类") {
        this.formUrl.value =
          this.formUrl.value + "/pages/shop/supplier/supplier?cate=" + row.id;
        return;
      }
      if (row.url_title == "产品分类" && row.click_title != "供应商分类") {
        this.formUrl.value =
          this.formUrl.value + "/shop/shopsearch?cate_id=" + row.id;
      }
      if (row.url_title == "旅游产品分类") {
        this.formUrl.value =
          this.formUrl.value + "/tourshop/cate?cate_id=" + row.id;
      }
      if (row.url_title == "插件管理") {
        // this.formUrl.value = this.formUrl.value + row.url || "";
      }
      if (row.url_title == "商品选择") {
        this.formUrl.value =
          this.formUrl.value + "/pages/shop/shopdetail/shopdetail?id=" + row.id;
      }
      if (row.url_title == "文章添加") {
        this.formUrl.value =
          this.formUrl.value + "/pages/news/newsdetail/newsdetail?id=" + row.id;
      }
      if (row.url_title == "资讯分类") {
        this.formUrl.value = this.formUrl.value + "/news?cate_id=" + row.id;
      }
      if (row.url_title == "商品分类2") {
        this.formUrl.value = "/shop/shopslide?cate_id=" + row.id;
      }
    },
    editErMenu(str) {
      this.dioWxMenuEr = true;
      this.form.title = str.title;
      this.form.id = str.id;
    },
    fabuMenu() {
      var params = {};
      params = this.form;
      this.$api.getWechat.fabuMenu(params).then(res => {
        if (res.data.code == 200 && res.data.status == 1) {
          this.$fnc.alertSuccess({ text: "发布成功" }); //成功弹出框
        } else {
          this.$fnc.alertError(res.data.code_desc, res.data.result); //失败弹出框
        }
      });
      this.dioWxMenuEr = false;
    },
    subWxMenuEr() {
      var params = {};
      params = this.form;
      alert(1);
      this.$api.getWechat.updateWxMenu(params).then(res => {
        if (res.data.code == 200 && res.data.status == 1) {
          this.$fnc.alertSuccess({ text: "修改成功" }); //成功弹出框
          this.getWxMenu();
        } else {
          this.$fnc.alertError(res.data.code_desc, res.data.result); //失败弹出框
        }
      });
      this.dioWxMenuEr = false;
    },
    divEven(e) {
      this.showEdit = e.detail;
    },
    closeDio() {
      this.yimenus = "";
    },
    getTypes(num) {
      this.formUrl.types = num;
      if (num == 1) {
        this.formUrl.material = "";
      } else if (num == 2 || num == 3) {
        this.imgUrl = "";
        this.zhuId = "";
        this.fuId = [];
        this.zhuTitle = "";
        this.fuTitle = [];
        this.danxuan = "";
        this.dialogTableVisible = true;
        this.formUrl.value = " ";
      } else {
        this.formUrl.value = " ";
      }
    },
    subItem(item) {
      this.danxuan = item;
      this.dialogTableVisible = false;
      this.formUrl.material = item.id;
    },
    setZhu(item) {
      console.log(this.fuId.indexOf(item.id) >= 0);
      if (this.fuId.indexOf(item.id) >= 0) {
        this.$fnc.alertError("选择错误", "主图文不能与副图文一样");
        return false;
      }
      this.zhuTitle = item;
      this.zhuId = item.id;
    },
    setFu(item) {
      if (this.zhuId == "") {
        this.$message.error("请先选择主标题");
        return false;
      }
      if (this.fuId.indexOf(item.id) >= 0) {
        this.fuId.splice(this.fuId.indexOf(item.id), 1);
        this.fuTitle.splice(this.fuId.indexOf(item.id), 1);
        return false;
      }
      if (this.fuTitle.length <= 8) {
        this.fuTitle.push(item);
        this.fuId.push(item.id);
      } else {
        this.$message.error("最对只能有8个副标题");
        return false;
      }
    },
    getWxMenu() {
      var data = {};
      this.$api.getWechat.getWxMenuList(data).then(res => {
        if (res.data.code == 200 && res.data.status == 1 && res.data.result) {
          if (res.data.result == null) {
            this.yiMen = [];
            return false;
          }
          this.yiMen = res.data.result;
        }
      });
    },
    addMenu(num, i) {
      if (num == 0) {
        if (this.yiMen.length >= 3) {
          this.$swal("错误", "最多只能选择3个一级菜单", "error");
          return false;
        }
      } else {
        if (num.z && num.z.length >= 5) {
          this.$swal("错误", "最多只能选择5个二级菜单", "error");
          return false;
        }
      }
      this.addInedx = i;
      this.dioWxMenu = true;
      this.updateId = "";
    },
    subWxMenu() {
      var obg = {};
      if (this.yimenus == "") {
        this.$message.error("一级菜单不能为空");
        return false;
      } else if (this.updateId) {
        obg.title = this.yimenus;
        obg.id = this.updateId;
        this.$api.getWechat.updateWxMenu(obg).then(res => {
          if (res.data.code == 200 && res.data.status == 1) {
            this.$fnc.alertSuccess({ text: "修改成功" }); //成功弹出框
            this.getWxMenu();
            console.log(obg.title);
            this.formUrl.title = obg.title;
            this.form.title = obg.title;
          } else {
            this.$fnc.alertError(res.data.code_desc, res.data.result); //失败弹出框
          }
        });
      } else if (this.addInedx == undefined) {
        obg.title = this.yimenus;
        obg.types = "0";
        this.$api.getWechat.addWxMenu(obg).then(res => {
          if (res.data.code == 200 && res.data.status == 1 && res.data.result) {
            this.$fnc.alertSuccess({ text: "添加成功" }); //成功弹出框
            this.getWxMenu();
          } else {
            this.$fnc.alertError(res.data.code_desc, res.data.result); //失败弹出框
          }
        });
      } else {
        obg.title = this.yimenus;
        obg.parent_id = this.yiMen[this.addInedx].id;
        this.yiMen[this.addInedx].z = [];
        this.yiMen[this.addInedx].z.push(obg);
        var _this = this;
        this.$api.getWechat.addWxMenu(obg).then(res => {
          if (res.data.code == 200 && res.data.status == 1 && res.data.result) {
            this.$fnc.alertSuccess({ text: "添加成功" }); //成功弹出框
            _this.getWxMenu();
          } else {
            this.$fnc.alertError(res.data.code_desc, res.data.result); //失败弹出框
          }
        });
      }
      this.yimenus = "";
      this.dioWxMenu = false;
    },
    toTypes(str) {
      var type = this.formUrl.types;
      if (str == "信息") {
        if (
          this.formUrl.material &&
          (this.formUrl.types == 2 || this.formUrl.types == 3)
        ) {
          var params = {};
          var id = this.formUrl.material;
          params.id_str = id;
          this.$api.getWechat.selectMaterialItems(params).then(res => {
            if (
              res.data.code == 200 &&
              res.data.status == 1 &&
              res.data.result &&
              this.formUrl.types == 2
            ) {
              this.danxuan = res.data.result[0];
            } else {
              var res = res.data.result;
              this.zhuTitle = res[0].title;
              this.zhuId = res[0].id;
              this.fuTitle = res.slice(1);
              for (var i in this.fuTitle) {
                this.fuId.push(this.fuTitle[i].id);
              }
            }
          });
        }
      }
      this.showTypes = str;
      this.showDefault = 5;
    },
    showMenu(e, item, i) {
      this.showTypes = "";
      this.acTitle = item.title;
      this.updateId = item.id;
      if (item.value == null) {
        item.value = "";
      }
      this.formUrl = item;
      console.log(this.formUrl);

      this.appid = this.formUrl.appid;
      this.appUrl = this.formUrl.value;
      this.appPage = this.formUrl.pagepath;

      if (item.z) {
        if (item.z.length > 0) {
          this.showDefault = 2;
        } else {
          this.showDefault = 1;
        }
      } else {
        this.showDefault = 1;
      }
    },
    editSave(str) {
      // if(str==6){
      //     this.formUrl.types=6;
      //     this.formUrl.material=this.url;
      // }else if(str==7){
      //     this.formUrl.types=7;
      //     this.formUrl.material=this.form.appid;
      //     this.formUrl.value=this.form.appUrl;
      // }
      // if(this.formUrl.types==5){
      //     this.formUrl.material="../../assets/img/tpl3.png";
      // }

      if (str == 1) {
        //跳转
        this.formUrl.types = 1;
        // this.formUrl.value = this.formUrl.value;
      }

      if (str == 8) {
        //小程序

        this.formUrl.types = 8;
        this.formUrl.appid = this.form.appid;
        this.formUrl.value = this.form.appUrl;
        this.formUrl.pagepath = this.form.pagePath;
      }

      var params = {};
      if (this.updateId) {
        if (this.formUrl.types == 3) {
          this.formUrl.material = this.zhuId + "@" + this.fuId.join("@");
        }
        params = this.formUrl;

        params.id = this.updateId;
        this.$api.getWechat.updateWxMenu(params).then(res => {
          if (res.data.code == 200 && res.data.status == 1 && res.data.result) {
            this.$fnc.alertSuccess({ text: "添加成功" }); //成功弹出框
            this.getWxMenu();
          } else {
            this.$fnc.alertError(res.data.code_desc, res.data.result); //失败弹出框
          }
        });
      }
    },
    delMenu(row, index, i) {
      this.$swal({
        title: "您确定要删除这条信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思"
      }).then(willDelete => {
        if (willDelete.value) {
          var params = {};
          params.id = row.id;
          this.$api.getWechat.deleteWxMenu(params).then(res => {
            if (res.data.code == 200) {
              if (row.parent_id == 0) {
                this.yiMen.splice(index, 1);
              } else {
                this.yiMen[i].z.splice(index, 1);
              }
              this.$swal("删除成功！", "您已经删除了这条信息。", "success");
            } else {
              this.$swal("删除失败！", "出错啦！", "success");
            }
          });
        }
      });
    },
    editMenu(row) {
      console.log(row);
      this.yimenus = row.title;
      this.updateId = row.id;
      this.dioWxMenu = true;
    },
    onSuccess(pic) {
      this.form.material = pic;
      this.imgUrl = this.$fnc.getImgUrl(pic);
    },
    upGo(fieldData, index) {
      if (index != 0) {
        fieldData[index] = fieldData.splice(index - 1, 1, fieldData[index])[0];
      } else {
        fieldData.push(fieldData.shift());
      }
      var str_sort = [];
      for (var i in fieldData) {
        str_sort.push(fieldData[i].id);
      }
      var str = str_sort.join("@");
      var parent_id = fieldData[0].parent_id;
      this.sortMenu(str, parent_id);
    },
    downGo(fieldData, index) {
      if (index != fieldData.length - 1) {
        fieldData[index] = fieldData.splice(index + 1, 1, fieldData[index])[0];
      } else {
        fieldData.unshift(fieldData.splice(index, 1)[0]);
      }
      var str_sort = [];
      for (var i in fieldData) {
        str_sort.push(fieldData[i].id);
      }
      var str = str_sort.join("@");
      var parent_id = fieldData[0].parent_id;
      this.sortMenu(str, parent_id);
    },
    sortMenu(str, parent_id) {
      str = str || "";
      var params = {};
      params.parent_id = parent_id;
      params.sort_str = str;
      this.$api.getWechat.sortWxMenu(params).then(res => {
        if (!res.data.result) {
          this.$fnc.alertError(res.data.code_desc, res.data.result); //失败弹出框
        }
      });
    },
    handleSizeChange(val) {
      this.$store.dispatch("getWx_material", {
        title: "",
        page: "",
        page_size: val
      });
      this.pageSize = val;
    },
    handleCurrentChange(val) {
            this.currentPage = val;
      this.$store.dispatch("getWx_material", {
        title: "",
        page: val,
        page_size: this.pageSize
      });
    },
    fanhui() {
      this.showTypes = "";
      this.showDefault = 1;
    }
  },
  computed: {
    getSuai() {
      return this.$store.state.wx_material;
    }
  },
  getSuai(obj) {
    console.log(obj);
    this.onewenbData = obj.data;
    this.all_num = obj.all_num;
  },
  watch: {
    dialogTableVisible(val) {
      this.$store.dispatch("getWx_material", {
        title: "",
        page: 1,
        page_size: 10
      });
      this.onewenbData = this.$store.state.wx_material.data;
      this.all_num = this.$store.state.wx_material.all_num;
    },
    search(val) {
      this.$store.dispatch("getWx_material", {
        title: val,
        page: "",
        page_size: ""
      });
    },
    fuId(val) {
      for (var i in val) {
        if (this.zhuId == val[i]) {
          this.fuId.splice(i, 1);
          this.fuTitle.splice(i, 1);
          this.$fnc.alertError("选择错误", "主图文不能与副图文一样");
        }
      }
    }
  }
};
</script>
